package eazy.DynamicProgramming;

public class _121maxProfit {
    public static void main(String[] args) {
        int[] a =new int[]{7,1,5,3,6,4};
        _121maxProfit _121maxProfit = new _121maxProfit();
        int i = _121maxProfit.maxProfit(a);
        System.out.println(i);
    }
    //炒股票
    public int maxProfit(int[] prices){
        int min = Integer.MAX_VALUE;
        int maxValue = 0;
        for (int price : prices) {
            if(price > min) {
                maxValue = Math.max(maxValue, price - min);
            } else {
                min = price;
            }
        }
        return maxValue;
    }
}
